package com.shwread.android.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shwread.android.qysw10000227.R;

public class ReaderMenuItem
        extends
        LinearLayout
{
	
	private ImageView imageView;
	private TextView  textView;
	
	public ReaderMenuItem(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public void init(String txtRes, int imageRes) {
		imageView = (ImageView) findViewById(R.id.reader_menu_item_iv);
		textView = (TextView) findViewById(R.id.reader_menu_item_tv);
		textView.setText(txtRes);
		imageView.setImageResource(imageRes);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (textView != null)
		{
			switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
					textView.setTextColor(0xFF00BC88);
					imageView.setPressed(true);
					break;
				case MotionEvent.ACTION_MOVE:
					boolean inx = event.getX() > 0 && event.getX() < getWidth();
					boolean iny = event.getY() > 0 && event.getY() < getHeight();
					if (inx && iny)
					{
						textView.setTextColor(0xFF00BC88);
						imageView.setPressed(true);
					}
					else
					{
						textView.setTextColor(0xFFF3F3F3);
						imageView.setPressed(false);
					}
					break;
				case MotionEvent.ACTION_UP:
					textView.setTextColor(0xFFF3F3F3);
					imageView.setPressed(false);
					break;
				default:
					break;
			}
		}
		return super.onTouchEvent(event);
	}
	
	public void changeTextRes(int txtRes) {
		textView.setText(txtRes);
	}
	
	public void changeImageRes(int imageRes) {
		imageView.setImageResource(imageRes);
	}
}
